<template>
  <div class="bgLogo">
    <img class="companyIntroduceLogo" src="@/assets/img/topLogo@3.png" alt="">
    <div class="login-center">
      <div class="companyIntroduce">
        <img src="@/assets/img/bgLeft.png" alt="">
      </div>
      <el-form :model="loginForm" :rules="rules" ref="loginForm" class="login-form">
        <el-form-item prop="name">
          <el-input v-model="loginForm.name" placeholder="用户名"/>
        </el-form-item>
        <el-form-item prop="password">
          <el-input @keydown.enter.native="doLogin" type="password" v-model="loginForm.password"
                    placeholder="密码" show-password/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loginLoading" @click="doLogin">登录</el-button>
        </el-form-item>
      </el-form>

    </div>
    <div class="footer">
      <a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=31011502017660" target="_blank">沪公网安备
        31011502017660号</a>&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="http://beian.miit.gov.cn" target="_blank">沪ICP备2021011432号-1</a>
    </div>
  </div>
</template>

<script>
import md5 from 'js-md5';

export default {
  name: 'Login.vue',
  data() {
    return {
      loginLoading: false,
      loginForm: {
        name: null,
        password: null,
      },
      rules: {
        name: [{required: true, message: '请输入用户名'}],
        password: [{required: true, message: '请输入密码'}],
      },
    }
  },
  async mounted() {
    await this.$store.dispatch('_setNeedRestPwd', false)
  },
  methods: {
    async doLogin() {
      this.loginLoading = true
      try {
        const data = await this.$post(this.$api.user.token, JSON.stringify({
          account: this.loginForm.name,
          password: md5(this.loginForm.password),
        }))
        await this.$store.dispatch('_setToken', data)
        await this.$router.push('/')
      } catch (e) {
        console.error(e)
      } finally {
        this.loginLoading = false
      }

    },
  },
}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/base";

.el-button--primary {
  background-color: #3364B7;
  border-color: #3364B7;
}

.bgLogo {
  position: absolute;
  width: 100%;
  height: 100%;
  background: url("~@/assets/img/bg@2.png") no-repeat;
  background-size: cover;
  display: flex;
  align-items: center;
}

img.companyIntroduceLogo {
  top: 1.5%;
  position: absolute;
  left: 4.5%;
  width: 80px;
}

.companyIntroduce {
  width: 50%;

  img {
    width: 50%;
    margin: 15px 80px 0 0;
    float: right;
  }
}

.login-center {
  width: 47%;
  display: flex;
  flex-direction: row;
  margin: 0 auto;
  padding: 60px 0 40px;
  background: rgba(249, 249, 249, 0.18);
  box-shadow: 8px 5px 33px #d0d0d0;
}

.login-form {
  width: 50%;
  margin: 10px 30px;

  .el-input {
    width: 250px;
  }

  .el-button {
    min-width: 140px;
  }
}

@media (max-width: 768px) {
  .companyIntroduce {
    width: 0;
    display: none;
  }
  .login-center {
    width: 90%;
  }
}

.footer {
  position: fixed;
  bottom: 10px;
  width: 100%;
  text-align: center;
  font-size: 12px;

  a {
    color: #404040;
    text-decoration: none;
  }

  a:hover {
    color: #047bb9;
  }
}

</style>
